New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for broken model.Model#remove by foreign key #379
Conversation
Actually in the docs |
Well, you're probably right. I didn't even consider this. It turns out almost every feature of 'model' I'm trying to use is broken or incomplete. |
You can remove multiple items in a single call, pass in an array of IDs. It's in the tests. On Jun 4, 2013, at 8:39 AM, Alexander Morokhovets notifications@github.com wrote:
|
ben-ng, It would be two calls actually. Get IDs + delete. |
ben-ng, { [error: syntax error at or near ")"]
length: 83,
name: 'error',
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '67',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'scan.l',
line: '1001',
routine: 'scanner_yyerror' } I've tried both: Model.remove(idsArray) and Model.remove({id: idsArray}) |
Sorry it's taken so long to have a look at this. There seem to be a lot of separate issues here. It looks like from your patch that the breakage happens only in the realtime code. Is that correct? We do have both unit and integration tests, although we don't have as much coverage as we'd like. There's a shared integration test for removing by an ID, or an array of IDs, and they pass in Postgres. As far as the other issues: -- What does "eager loading for fields with non-default names" mean? Are you talking about named associations? |
I'm not sure of what you mean. If "realtime code" == "code executed on client" then no it's a server side controller action code.
Well when I was elaborating on this bug It was clear from the source code that it would break.
It turned out that bug occurs when you try to use associations with compund class names, e.g: Server = ->
hasMany "DbConfigs"
geddy.model.Server.first {includes: "dbConfigs"}, (err, server) =>
console.log server.dbConfigs #=> undefined
geddy.model.Server.first {includes: "db_configs"}, (err, server) => # snake case
console.log server.db_configs #=> actual array of configs, snake case only as well
User = ->
hasMany 'bindings', model: 'UserBinding'
geddy.model.User.first {}, (err, user) =>
user.addBinding geddy.model.UserBinding.create(blah: "blah") #=> addBinding is not a function
geddy.model.User.first {}, (err, user) =>
user.addbinding geddy.model.UserBinding.create(blah: "blah") #=> OK Thanks for your response! |
All right, so I've pushed a Geddy update that fixes that problem of reference pollution in app/index.js. This is on NPM, v0.8.12. Let me know if this fixes your problem removing associated items by their foreign key. For future reference, the The problem with the 'includes' query condition has an (already fixed) issue here: geddy/model#68 I'm going to have to dig a little more on the issue you're having with 'addBinding' -- we have tests that cover this (using 'addProfile'), and they work correctly. |
Your problem with your 'Binding' association is that you lowercased the name in the hasMany call. The current code expected a model definition name (i.e., the constructor). I've updated the code to normalize this better. Fix is in 15c506dcf2ff200c6edeae082213247929a6a765. |
Try something like:
It will break with
Tracking this down I've found that in geddy/lib/app/index.js there's a hook on 'beforeRemove' event that changes query conditions object adding 'model' and 'event' attributes in there.
The patch is just a simple workaround for this problem.
Not sure of the best way to fix.